//
//  BoozeUtils.m
//  VeganIsEasy
//
//  Created by Matthew Feinberg on 2/13/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "BoozeUtils.h"
#import "ConnectivityTest.h"
#import "Utils.h"

@implementation BoozeUtils

+ (NSString *)formatDateString:(NSString *)dateString {

	if (dateString == nil || [dateString length] < 10) {
		return nil;
	}
	
	NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
	[formatter autorelease];

	[formatter setDateFormat:@"yyyy-mm-dd"];
	dateString = [dateString substringToIndex:10];
	NSDate *date = [formatter dateFromString:dateString];
	if (date == nil) {
		return nil;
	}
	
	[formatter setDateStyle:NSDateFormatterMediumStyle];
	[formatter setTimeStyle:NSDateFormatterNoStyle];
//	[formatter setDateFormat:@"EEE dd, yyyy"];
	return [formatter stringFromDate:date];
}

+ (void)openUrlString:(NSString *)urlString {
	NSURL *url = [NSURL URLWithString:urlString];

	if (![[url scheme] isEqualToString:@"mailto"] && ![ConnectivityTest hostAvailable:[url host]]) {
		[Utils alertWithMessage:@"The page can not be opened, because you are not connected to the Internet." andTitle:@"Network error"];
	}
	else {
		[[UIApplication sharedApplication] openURL:url];
	}
}	


@end
